package fun._6742.model.valueobject;

import fun._6742.model.dataobject.CartItemDO;
import fun._6742.request.CartItemRequest;
import lombok.*;

import java.math.BigDecimal;

@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CartItemVO {
    /**
     * 商品id
     */
    private Long productId;
    private String name;

    private String coverImg;

    private Long cartId;

    /**
     * 购买数量
     */
    private Integer productNum;

    /**
     * 商品单价
     */
    private BigDecimal price;

    /**
     * 总价格 ( 单价*数量 )
     */
    private BigDecimal totalPrice;
    private Integer goods_status;


    public CartItemVO(CartItemRequest cartItemRequest) {
        this.productId = cartItemRequest.getId();
        this.productNum = cartItemRequest.getNum();
    }

    public CartItemVO(CartItemDO cartItemDO, ProductVO productVO) {
        this.name = productVO.getTitle();
        this.productId = cartItemDO.getProductId();
        this.cartId = cartItemDO.getCartId();
        this.productNum = cartItemDO.getProductNum();
        this.price = productVO.getPrice();
        this.coverImg = productVO.getCoverImg();
        this.totalPrice = price.multiply(BigDecimal.valueOf(productNum));
        this.goods_status = cartItemDO.getGoodsStatus();
    }

    public BigDecimal getTotalPrice() {
        this.totalPrice = this.price.multiply(new BigDecimal(this.productNum));
        return this.price.multiply(new BigDecimal(this.productNum));
    }
}
